home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / DistUpgrade / DistUpgradeMain.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  4.3 KB  |  98 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from DistUpgradeController import DistUpgradeController
  5. from DistUpgradeConfigParser import DistUpgradeConfig
  6. import logging
  7. import os
  8. import sys
  9. import glob
  10. import shutil
  11. from datetime import datetime
  12. from optparse import OptionParser
  13. from gettext import gettext as _
  14.  
  15. def do_commandline():
  16.     ''' setup option parser and parse the commandline '''
  17.     parser = OptionParser()
  18.     parser.add_option('-s', '--sandbox', dest = 'useAufs', default = False, action = 'store_true', help = _('Sandbox upgrade using aufs'))
  19.     parser.add_option('-c', '--cdrom', dest = 'cdromPath', default = None, help = _('Use the given path to search for a cdrom with upgradable packages'))
  20.     parser.add_option('--have-prerequists', dest = 'havePrerequists', action = 'store_true', default = False)
  21.     parser.add_option('--with-network', dest = 'withNetwork', action = 'store_true')
  22.     parser.add_option('--without-network', dest = 'withNetwork', action = 'store_false')
  23.     parser.add_option('--frontend', dest = 'frontend', default = None, help = _('Use frontend. Currently available: \nDistUpgradeViewText, DistUpgradeViewGtk, DistUpgradeViewKDE'))
  24.     parser.add_option('--mode', dest = 'mode', default = 'desktop', help = _('*DEPRECATED* this option will be ignore'))
  25.     parser.add_option('--partial', dest = 'partial', default = False, action = 'store_true', help = _('Perform a partial upgrade only (no sources.list rewriting)'))
  26.     parser.add_option('--datadir', dest = 'datadir', default = None, help = _('Set datadir'))
  27.     return parser.parse_args()
  28.  
  29.  
  30. def setup_logging(options, config):
  31.     ''' setup the logging '''
  32.     logdir = config.getWithDefault('Files', 'LogDir', '/var/log/dist-upgrade/')
  33.     if not os.path.exists(logdir):
  34.         os.mkdir(logdir)
  35.     
  36.     if glob.glob(logdir + '/*.log'):
  37.         now = datetime.now()
  38.         backup_dir = logdir + '/%04i%02i%02i-%02i%02i' % (now.year, now.month, now.day, now.hour, now.minute)
  39.         if not os.path.exists(backup_dir):
  40.             os.mkdir(backup_dir)
  41.         
  42.         for f in glob.glob(logdir + '/*.log'):
  43.             shutil.move(f, os.path.join(backup_dir, os.path.basename(f)))
  44.         
  45.     
  46.     fname = os.path.join(logdir, 'main.log')
  47.     if options.partial:
  48.         fname += '.partial'
  49.     
  50.     logging.basicConfig(level = logging.DEBUG, filename = fname, format = '%(asctime)s %(levelname)s %(message)s', filemode = 'w')
  51.     logging.info("Using config files '%s'" % config.config_files)
  52.     return logdir
  53.  
  54.  
  55. def setup_view(options, config, logdir):
  56.     ''' setup view based on the config and commandline '''
  57.     for requested_view in [
  58.         options.frontend] + config.getlist('View', 'View'):
  59.         if not requested_view:
  60.             continue
  61.         
  62.         
  63.         try:
  64.             view_modul = __import__(requested_view)
  65.             view_class = getattr(view_modul, requested_view)
  66.         continue
  67.         except (ImportError, AttributeError, TypeError):
  68.             e = None
  69.             logging.warning("can't import view '%s' (%s)" % (requested_view, e))
  70.             print "can't load %s (%s)" % (requested_view, e)
  71.             continue
  72.         
  73.  
  74.     else:
  75.         print 'No view can be imported, aborting'
  76.         sys.exit(1)
  77.     return view_class(logdir = logdir)
  78.  
  79.  
  80. def main():
  81.     ''' main method '''
  82.     (options, args) = do_commandline()
  83.     config = DistUpgradeConfig('.')
  84.     logdir = setup_logging(options, config)
  85.     VERSION = VERSION
  86.     import DistUpgradeVersion
  87.     logging.info("release-upgrader version '%s' started" % VERSION)
  88.     view = setup_view(options, config, logdir)
  89.     app = DistUpgradeController(view, options, datadir = options.datadir)
  90.     if options.partial:
  91.         if not app.doPartialUpgrade():
  92.             sys.exit(1)
  93.         
  94.         sys.exit(0)
  95.     
  96.     app.run()
  97.  
  98.